package com.fucheng.server;

import com.fucheng.api.CalculatorService;
import com.fucheng.api.HelloService;
import com.fucheng.registry.ZookeeperServiceRegistry;
import com.fucheng.server.serviceImpl.CalculatorServiceImpl;
import com.fucheng.server.serviceImpl.HelloServiceImpl;
import com.fucheng.transport.NettyRpcServer;


/**
 * NettyRpcServer启动 + Zookeeper注册服务地址
 */
public class RpcServer {

    public static void main(String[] args) {

        int port = 8888;
        String host = "127.0.0.1";
        String serviceAddress = host + ":" + port;

        // 注册中心实例
        ZookeeperServiceRegistry registry = new ZookeeperServiceRegistry();

        // 创建服务配置
        ServiceConfig<HelloService> helloConfig =
                new ServiceConfig<>(HelloService.class, new HelloServiceImpl(), "1.0", "helloService");

        ServiceConfig<CalculatorService> calcConfig =
                new ServiceConfig<>(CalculatorService.class, new CalculatorServiceImpl(), "1.0", "calculatorService");

        // 注册服务到本地服务表
        ServerRegistry.register(helloConfig);
        ServerRegistry.register(calcConfig);

        // 注册服务到 Zookeeper
        registry.register("helloService:1.0", serviceAddress);
        registry.register("calculatorService:1.0", serviceAddress);

        // 启动 Netty RPC 服务端
        new NettyRpcServer(port).start();


    }
}
